#include<stdio.h>
#include<string.h>                                                              
#include<unistd.h>
#include<pthread.h>
#include<fcntl.h>
#include<wait.h>
#include<errno.h>

int main(int argc, char* argv[])
{
    int pipefd[2];
    pipe(pipefd);
    int pid=fork();
    char buf[1024];
    if(pid==0)
    {
        //子进程写数据，关闭读端
        close(pipefd[0]);
        //输出到管道
        dup2(pipefd[1],1);
        execlp("ls","ls","/",NULL);
        
    }
    else
    {
        //父进程读数据，关闭写端
        close(pipefd[1]);
        //读管道
        dup2(pipefd[0],0);
        execlp("wc","wc","-l",NULL);
        
        int status;
        int wpid=wait(&status);
        if(WIFSIGNALED(status))
        {
            printf("child return value=%d\n",WTERMSIG (status));
        }
    }
    while(1);
}


